package cn.poco.pepsi.util.xmlpared;

import java.io.InputStream;
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParser;

import android.util.Xml;
import cn.poco.pepsi.bean.Area;
import cn.poco.pepsi.bean.DiscutByArea;

public class DiscutByAreaXmlparse {
	//private final static String TAG = "DisAreaXmlparse";
	private static ArrayList<DiscutByArea> discuts = null;
	private static  DiscutByArea discutBean = null;
	
	public static ArrayList<DiscutByArea> getXml(InputStream inSteam) throws Exception{
		XmlPullParser xmpparse = Xml.newPullParser();   //寰楀埌瑙ｉ噴鍣�
		xmpparse.setInput(inSteam, "UTF-8");           //璁剧疆瑙ｉ噴娴�
		int code = xmpparse.getEventType();            //寰楀埌鑺傜偣淇℃伅
		while(code!=XmlPullParser.END_DOCUMENT){
			switch (code) {
			case XmlPullParser.START_DOCUMENT:
				discuts = new ArrayList<DiscutByArea>();
				break;
			case XmlPullParser.START_TAG:
				if("area".equals(xmpparse.getName())){
					discutBean = new DiscutByArea();
				}
				if(discutBean!=null){
					if("key".equals(xmpparse.getName())){
						String key = xmpparse.nextText();
						discutBean.setKey(key);
					}
					if("name".equals(xmpparse.getName())){
						String name = xmpparse.nextText();
						discutBean.setName(name);
					}
					if("discount-cnt".equals(xmpparse.getName())){
						String discountcnt = xmpparse.nextText();
						
							discutBean.setDiscountN(discountcnt);
					}
				}
				break;
			case XmlPullParser.END_TAG:
				if("area".equals(xmpparse.getName())){
					if(Integer.parseInt(discutBean.getDiscountN())!=0){
						discuts.add(discutBean);
					}
					
					discutBean = null;
				}
				break;
			}	
			code = xmpparse.next();
		}
		inSteam.close();
		return discuts;
	}
}
